home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Mesa-2.2 / src / ADisp_Cyb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-25  |  45.7 KB  |  1,509 lines

  1. /* $Id: $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Library General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15.  * Library General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Library General Public
  18.  * License along with this library; if not, write to the Free
  19.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  */
  21.  
  22. /*
  23. $Log:  $
  24.  */
  25.  
  26.  
  27. /*
  28. TODO:
  29. Dynamic allocate the vectorbuffer for polydrawing. (memory improvment)
  30. implement shared list.
  31. fix resizing bug.
  32. some native asm rutine
  33. fast asm line drawin in db mode
  34. fast asm clear       in db mode
  35. read buffer rutines  in db-mode
  36.  
  37. IDEAS:
  38. */
  39.  
  40.  
  41. /*
  42.  * Note that you'll usually have to flip Y coordinates since Mesa's
  43.  * window coordinates start at the bottom and increase upward.  Most
  44.  * window system's Y-axis increases downward
  45.  *
  46.  * See dd.h for more device driver info.
  47.  * See the other device driver implementations for ideas.
  48.  *
  49.  */
  50.  
  51. #include <gl/AmigaMesa.h>
  52.  
  53. #ifdef ADISP_CYBERGFX
  54. /* This ifdef outcomment the whole file if you havent specified ADISP_CYBERGFX flag */
  55.  
  56. #include "ADisp_Cyb.h"
  57.  
  58. #ifdef __GNUC__
  59. #include "../amiga/misc/ht_colors.h"
  60. #else
  61. #include "/amiga/misc/ht_colors.h"
  62. #endif
  63.  
  64. #include <exec/memory.h>
  65. #include <exec/types.h>
  66. #ifdef __GNUC__
  67. #include <inline/exec.h>
  68. #include <inline/intuition.h>
  69. #include <inline/graphics.h>
  70. #include <inline/utility.h>
  71. #include <inline/cybergraphics.h>
  72. extern struct Library*  CyberGfxBase;
  73. #else
  74. #include <proto/exec.h>
  75. #include <proto/intuition.h>
  76. #include <proto/graphics.h>
  77. #include <proto/utility.h>
  78. #include <proto/cybergraphics.h>
  79. #include <cybergraphics/cybergraphics.h>
  80. #endif
  81.  
  82. #include <stdlib.h>
  83. #include <stdio.h>
  84. #include <gl/gl.h>
  85. #include "context.h"
  86. #include "dd.h"
  87. #include "xform.h"
  88. #include "macros.h"
  89. #include "vb.h"
  90.  
  91. #define MAX_POLYGON 300
  92.  
  93. #define TC_RGBA(r,g,b,a) ((((((a<<8)|r)<<8)|g)<<8)|b)
  94.  
  95. //#define DEBUGPRINT
  96.  
  97. #ifdef DEBUGPRINT
  98. #define DEBUGOUT(x) printf(x);
  99. #else
  100. #define DEBUGOUT(x) /*printf(x);*/
  101. #endif
  102.  
  103. extern void amiga_Faster_DD_pointers( GLcontext *ctx );
  104. extern void amiga_standard_DD_pointers( GLcontext *ctx );
  105.  
  106. /**********************************************************************/
  107. /*****                Some Usefull code                                     *****/
  108. /**********************************************************************/
  109.  
  110. /*
  111.     The Drawing area is defined by:
  112.  
  113.     CC.Viewport.X = x;
  114.     CC.Viewport.Width = width;
  115.     CC.Viewport.Y = y;
  116.     CC.Viewport.Height = height;
  117. */
  118.  
  119. static void Cyb_Standard_resize( GLcontext *ctx,GLuint *width, GLuint *height);
  120. static void Cyb_Standard_resize_db( GLcontext *ctx,GLuint *width, GLuint *height);
  121. extern UBYTE* alloc_penbackarray( int width, int height, int bytes);
  122. extern void destroy_penbackarray(UBYTE *buf);
  123. extern struct RastPort *make_rastport( int width, int height, int depth, struct BitMap *friendbm );
  124. extern void destroy_rastport( struct RastPort *rp );
  125. extern void AllocOneLine(struct amigamesa_context *AmigaMesaCreateContext);
  126. extern void FreeOneLine(struct amigamesa_context *AmigaMesaCreateContext);
  127. //#define RGBA(r,g,b,a) ((((((a<<8)|r)<<8)|g)<<8)|b)
  128.  
  129. #define FIXx(x) (amesa->left + (x))
  130.  
  131. #define FIXy(y) (amesa->RealHeight-amesa->bottom - (y))
  132.  
  133. #define FIXxy(x,y) ((amesa->RealWidth*FIXy(y)+FIXx(x)))
  134.  
  135. /**********************************************************************/
  136. /*****                Miscellaneous device driver funcs                 *****/
  137. /**********************************************************************/
  138.  
  139. static void cyb_finish( void )
  140. {
  141.     /* implements glFinish if possible */
  142. }
  143.  
  144.  
  145. static void cyb_flush( void )
  146. {
  147.     /* implements glFlush if possible */
  148. }
  149.  
  150.  
  151. static void cyb_clear_index( GLcontext *ctx, GLuint index )
  152. {
  153.    /* implement glClearIndex */
  154.    /* usually just save the value in the context struct */
  155.    /*printf("aclear_index=glClearIndex=%d\n",index);*/
  156.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  157.    amesa->clearpixel = amesa->penconv[index];
  158. }
  159.  
  160.  
  161. static void cyb_clear_color( GLcontext *ctx,
  162.                           GLubyte r, GLubyte g, GLubyte b, GLubyte a )
  163. {
  164.    /* implement glClearColor */
  165.    /* color components are floats in [0,1] */
  166.    /* usually just save the value in the context struct */
  167.    /*printf("aclear_color=glClearColor(%d,%d,%d,%d)\n",r,g,b,a);*/
  168.    /* @@@ TODO FREE COLOR IF NOT USED */
  169.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  170.    amesa->clearpixel=TC_RGBA(r,g,b,a);
  171. }
  172.  
  173.  
  174.  
  175.  
  176. static void cyb_clear( GLcontext *ctx,GLboolean all, GLint x, GLint y, GLint width, GLint height )
  177. {
  178. /*
  179.  * Clear the specified region of the color buffer using the clear color
  180.  * or index as specified by one of the two functions above.
  181.  * If all==GL_TRUE, clear whole buffer
  182.  */
  183.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  184.  
  185. #ifdef DEBUGPRINT
  186. printf("cyb_clear(%d,%d,%d,%d,%d)\n",all,x,y,width,height);
  187. #endif
  188.  
  189.  
  190.     if(all)
  191.         {
  192.         FillPixelArray (amesa->rp,FIXx(ctx->Viewport.X),FIXy(ctx->Viewport.Y)-ctx->Viewport.Height+1,/*FIXx(ctx->Viewport.X)+*/ctx->Viewport.Width/*-1*/,ctx->Viewport.Height/*FIXy(ctx->Viewport.Y)*/,amesa->clearpixel);
  193.         }
  194.     else
  195.         {
  196.         if(amesa->rp!=0)
  197.             {
  198.             FillPixelArray (amesa->rp,FIXx(x),FIXy(y)-height,width,FIXy(y),amesa->clearpixel);
  199.             }
  200.         else
  201.             printf("Serius error amesa->rp=0 detected in cyb_clear() in file cybmesa.c\n");
  202.         }
  203.     
  204. }
  205.  
  206. static void cyb_clear_db(GLcontext *ctx, GLboolean all, GLint x, GLint y, GLint width, GLint height )
  207. {
  208. /*
  209.  * Clear the specified region of the color buffer using the clear color
  210.  * or index as specified by one of the two functions above.
  211.  * If all==GL_TRUE, clear whole buffer
  212.  */
  213.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  214. /*  int i; */
  215.     register ULONG *db;
  216.     register ULONG col=amesa->clearpixel;
  217.  
  218.  
  219. #ifdef DEBUGPRINT
  220. printf("cyb_clear_db(%d,%d,%d,%d,%d)\n",all,x,y,width,height);
  221. #endif
  222.  
  223.     if(all)
  224.         {
  225.         int x1,y1,x2,y2;
  226. //      RectFill(amesa->rp,FIXx(CC.Viewport.X),FIXy(CC.Viewport.Y)-CC.Viewport.Height+1,FIXx(CC.Viewport.X)+CC.Viewport.Width-1,FIXy(CC.Viewport.Y));
  227.  
  228.         x1=0;
  229.         y1=0;
  230.         x2=amesa->RealWidth;
  231.         y2=amesa->RealHeight;
  232.         db=(ULONG *)amesa->BackArray;
  233.         for(y1=0;y1<y2;y1++)
  234.             {
  235.             for(x1=0;x1<x2;x1++)
  236.                 {
  237.                 *db=col;db++;
  238.                 }
  239.             }
  240.         }
  241. //  return(((((amesa->RealWidth+15)>>4)<<4)*FIXy(y)+FIXx(x)));
  242.     else
  243.         {
  244.         int x1,y1,x2,y2;
  245. //      RectFill(amesa->rp,FIXx(x),FIXy(y)-height,width,FIXy(y));
  246.         x2=FIXx(x+width);
  247.         y2=FIXy(y);
  248.  
  249.         for(y1=FIXy(y)-height;y1<y2;y1++)
  250.             {
  251.             for(x1=FIXx(x);x1<x2;x1++)
  252.                 {
  253. //printf("clear byte 0x%x\n",&(amesa->BackArray[x1+y1*(((amesa->RealWidth+15)>>4)<<4)]));
  254.                 ((ULONG*)amesa->BackArray)[x1+y1*amesa->RealWidth]=col;
  255.                 }
  256.             }
  257.         }
  258. }
  259.  
  260.  
  261.  
  262. static void cyb_set_index( GLcontext *ctx,GLuint index )
  263. {
  264.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  265.  
  266.     /* Set the amesa color index. */
  267. /*printf("aset_index(%d)\n",index);*/
  268.     amesa->pixel = amesa->penconv[index];
  269. }
  270.  
  271.  
  272.  
  273. static void cyb_set_color( GLcontext *ctx,GLubyte r, GLubyte g, GLubyte b, GLubyte a )
  274. {
  275.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  276.  
  277. /*printf("cyb_set_color(%d,%d,%d,%d)\n",r,g,b,a);*/
  278.  
  279.         /* Set the current RGBA color. */
  280.         /* r is in 0..255.RedScale */
  281.         /* g is in 0..255.GreenScale */
  282.         /* b is in 0..255.BlueScale */
  283.         /* a is in 0..255.AlphaScale */
  284.     amesa->pixel = TC_RGBA(r,g,b,a);
  285. }
  286.  
  287.  
  288. static GLboolean cyb_index_mask( GLcontext *ctx,GLuint mask )
  289. {
  290.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  291.  
  292.     /* implement glIndexMask if possible, else return GL_FALSE */
  293. /*printf("cyb_index_mask(0x%x)\n",mask);*/
  294.     amesa->rp->Mask = (UBYTE) mask;
  295.  
  296.     return(GL_TRUE);
  297. }
  298.  
  299. static GLboolean cyb_color_mask( GLcontext *ctx,GLboolean rmask, GLboolean gmask,
  300.                                       GLboolean bmask, GLboolean amask)
  301. {
  302.     /* implement glColorMask if possible, else return GL_FALSE */
  303.     return(GL_FALSE);
  304.  
  305. }
  306.  
  307.  
  308.  
  309. /**********************************************************************/
  310. /*****            Accelerated point, line, polygon rendering      *****/
  311. /**********************************************************************/
  312.  
  313. /*
  314.  *  Render a number of points by some hardware/OS accerated method
  315.  */
  316.  
  317. static void cyb_fast_points_function(GLcontext *ctx,GLuint first, GLuint last )
  318. {
  319.  
  320.  
  321.     AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  322.     struct vertex_buffer *VB = ctx->VB;
  323.  
  324.     int i,col;
  325.     register struct RastPort * rp=amesa->rp;
  326. /* printf("cyb_fast_points_function\n");*/
  327.  
  328.         if (VB->MonoColor) {
  329.         /* draw all points using the current color (set_color) */
  330. /*      printf("VB->MonoColor\n");*/
  331.         for (i=first;i<=last;i++) {
  332.             if (VB->Unclipped[i]) {
  333.                 /* compute window coordinate */
  334.                 int x, y;
  335.                 x =FIXx((GLint) (VB->Win[i][0]));
  336.                 y =FIXy((GLint) (VB->Win[i][1]));
  337.             WriteRGBPixel(rp,x,y,amesa->pixel);
  338. /*      printf("WriteRGBPixel(%d,%d)\n",x,y);*/
  339.             }
  340.         }
  341.     } else {
  342.         /* each point is a different color */
  343. /*      printf("!VB.MonoColor\n");*/
  344.  
  345.         for (i=first;i<=last;i++) {
  346.             /*if (VB.Unclipped[i])*/ {
  347.                 int x, y;
  348.                 x =FIXx((GLint) (VB->Win[i][0]));
  349.                 y =FIXy((GLint) (VB->Win[i][1]));
  350.                 col=*VB->Color[i];
  351.             WriteRGBPixel(rp,x,y,amesa->penconv[col]);
  352. /*      printf("WriteRGBPixel(%d,%d)\n",x,y);*/
  353.             }
  354.         }
  355.     }
  356. }
  357.  
  358.  
  359.  
  360. static points_func cyb_choose_points_function( GLcontext *ctx )
  361. {
  362. /*printf("cyb_choose_points_function\n");*/
  363.     /* Examine the current rendering state and return a pointer to a */
  364.     /* fast point-rendering function if possible. */
  365.    if (ctx->Point.Size==1.0 && !ctx->Point.SmoothFlag && ctx->RasterMask==0
  366.        && !ctx->Texture.Enabled /*&&  ETC, ETC */) {
  367.       return cyb_fast_points_function;
  368.    }
  369.    else {
  370.       return NULL;
  371.    }
  372. }
  373.  
  374. static points_func cyb_choose_points_function_db( GLcontext *ctx )
  375.     {
  376.     return NULL;
  377.     }
  378.  
  379.  
  380.  /*
  381.   *  Render a line by some hardware/OS accerated method 
  382.   */
  383.  
  384. static line_func cyb_choose_line_function( GLcontext *ctx)
  385. {
  386.     /*printf("cyb_choose_line_function\n");*/
  387.  
  388.     /* Examine the current rendering state and return a pointer to a */
  389.     /* fast line-rendering function if possible. */
  390.  
  391.     return NULL;
  392. }
  393.  
  394. static line_func cyb_choose_line_function_db( GLcontext *ctx)
  395.     {
  396.     return NULL;
  397.     }
  398.  
  399. /*
  400.  * Draw a filled polygon of a single color. If there is hardware/OS support
  401.  * for polygon drawing use that here.   Otherwise, call a function in
  402.  * polygon.c to do the drawing.
  403.  */
  404.  
  405. static polygon_func cyb_choose_polygon_function( GLcontext *ctx )
  406. {
  407.     /* printf("cyb_choose_polygon_function\n");*/
  408.  
  409.     /* Examine the current rendering state and return a pointer to a */
  410.     /* fast polygon-rendering function if possible. */
  411.  
  412.     return NULL;
  413. }
  414.  
  415. /**********************************************************************/
  416. /*****                  Optimized polygon rendering               *****/
  417. /**********************************************************************/
  418.  
  419.  
  420. static polygon_func cyb_choose_polygon_function_db( GLcontext *ctx )
  421. {
  422.     return NULL;
  423. }
  424.  
  425.  
  426. /**********************************************************************/
  427. /*****              Write spans of pixels                                   *****/
  428. /**********************************************************************/
  429.  
  430. static void cyb_write_index_span_db(GLcontext *ctx, GLuint n, GLint x, GLint y,
  431.                                             const GLuint index[],
  432.                                             const GLubyte mask[] )
  433. {
  434.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  435.  
  436.     int i/* ,ant*/;
  437.     register ULONG *db;
  438.     register unsigned long * penconv=amesa->penconv;
  439.  
  440.  
  441. #ifdef DEBUGPRINT
  442. printf("cyb_write_index_span_db(%d,%d,%d)\n",n,x,y);
  443. #endif
  444.  
  445.     db=&((ULONG*)amesa->BackArray)[FIXxy(x,y)];
  446.  
  447.     /* Slower */
  448.     if(mask)
  449.         {
  450.         for (i=0;i<n;i++)
  451.             {
  452.             if(mask[i])
  453.                 {
  454.                 /* draw pixel (x[i],y[i]) using index[i] */
  455.                 *db=penconv[index[i]];
  456.                 }
  457.                 db++;
  458.             }
  459.         }
  460.     else
  461.         for (i=0;i<n;i++)
  462.             {
  463.             /* draw pixel (x[i],y[i]) using index[i] */
  464.             *db=penconv[index[i]];db++;
  465.             }
  466.     }
  467.  
  468.  
  469. static void cyb_write_color_span_db(GLcontext *ctx, GLuint n, GLint x, GLint y,
  470.                                         const GLubyte red[], const GLubyte green[],
  471.                                         const GLubyte blue[], const GLubyte alpha[],
  472.                                         const GLubyte mask[])
  473. {
  474.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  475.     int i/*,ant*/;
  476.     register ULONG *db;
  477.  
  478. #ifdef DEBUGPRINT
  479. printf("cyb_write_color_span_db(%d,%d,%d)\n",n,x,y);
  480. #endif
  481.  
  482.     db=&((ULONG*)amesa->BackArray)[FIXxy(x,y)];
  483. /* Slower */
  484.     if (mask)
  485.         {
  486.         for (i=0;i<n;i++)
  487.             {
  488.             if (mask[i])
  489.                 {
  490.                 /* draw pixel (x[i],y[i]) using index[i] */
  491.                 *db=TC_RGBA(red[i],green[i],blue[i],alpha[i]);
  492.                 }
  493.                 db++;
  494.             }
  495.         }
  496.     else
  497.         {
  498.         for (i=0;i<n;i++)
  499.             {
  500.             /* draw pixel (x[i],y[i]) using index[i] */
  501.             *db=TC_RGBA(red[i],green[i],blue[i],alpha[i]);db++;
  502.             }
  503.         }
  504.     
  505. }
  506. static void cyb_write_monoindex_span_db( GLcontext *ctx,GLuint n, GLint x, GLint y,const GLubyte mask[])
  507. {
  508.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  509.     int i/*,ant*/;
  510.     register ULONG *db;
  511.  
  512. #ifdef DEBUGPRINT
  513. printf("awrite_monoindex_span_db(%d,%d,%d)\n",n,x,y);
  514. #endif
  515.  
  516. db=&((ULONG*)amesa->BackArray)[FIXxy(x,y)];
  517.  
  518.     /* Slower */
  519. if(mask)
  520.     {
  521.     for (i=0;i<n;i++)
  522.         {
  523.         if (mask[i])
  524.             {
  525.             /* draw pixel (x[i],y[i]) using index[i] */
  526.             *db=amesa->pixel;
  527.             }
  528.             db++;
  529.         }
  530.     }
  531. else
  532.     for (i=0;i<n;i++)
  533.         {
  534.         /* draw pixel (x[i],y[i]) using index[i] */
  535.         *db=amesa->pixel;db++;
  536.         }
  537. }
  538.  
  539.  
  540. static void cyb_write_index_span(GLcontext *ctx, GLuint n, GLint x, GLint y,
  541.                                         const GLuint index[],
  542.                                         const GLubyte mask[] )
  543. {
  544.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  545.     int i,ant;
  546.     ULONG *dp;
  547.     unsigned long * penconv=amesa->penconv;
  548.     register struct RastPort * rp=amesa->rp;
  549.  
  550. /*printf("cyb_write_index_span(%d,%d,%d)\n",n,x,y);*/
  551. DEBUGOUT("cyb_write_index_span(n,x,y)\n")
  552.  
  553.     y=FIXy(y);
  554.     x=FIXx(x);
  555.     if(dp = (ULONG*)amesa->imageline)
  556.     {                     /* if imageline have been
  557.                         allocated then use fastversion */
  558.  
  559.         ant=0;
  560.             for (i=0;i<n;i++) { /* draw pixel (x[i],y[i]) using index[i] */
  561.                 if (mask[i]) {
  562.                     ant++;
  563. //              x++;
  564.                 *dp = penconv[index[i]];dp++;
  565.             } else {
  566.                 if(ant)
  567. DEBUGOUT("cyb_write_index_span: WritePixelArray()\n")
  568.                     WritePixelArray(amesa->imageline,0,0,4*ant,rp,x,y,ant,1,RECTFMT_ARGB);
  569.                 dp=(ULONG*)amesa->imageline;
  570.                 ant=0;
  571.                 x++;
  572.             }
  573.         }
  574.         if(ant)
  575. DEBUGOUT("cyb_write_index_span: WritePixelArray()\n")
  576.             WritePixelArray(amesa->imageline,0,0,4*ant,rp,x,y,ant,1,RECTFMT_ARGB);
  577.  
  578.     } else {            /* Slower */
  579.             for (i=0;i<n;i++,x++) {
  580.                 if (mask[i]) {
  581.                  /* draw pixel (x[i],y[i]) using index[i] */
  582.                 WriteRGBPixel(rp,x,y,penconv[index[i]]);
  583.             }
  584.         }
  585.     }
  586. }
  587.  
  588.  
  589. static void cyb_write_color_span( GLcontext *ctx,GLuint n, GLint x, GLint y,
  590.                                         const GLubyte red[], const GLubyte green[],
  591.                                         const GLubyte blue[], const GLubyte alpha[],
  592.                                         const GLubyte mask[] )
  593. {
  594.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  595.     int i,ant;
  596.     ULONG *dp;
  597.  
  598.     register struct RastPort * rp = amesa->rp;
  599.  
  600. /*DEBUGOUT("cyb_write_color_span(n,x,y) ")*/
  601.     
  602.     y=FIXy(y);
  603.     x=FIXx(x);
  604. /*printf("cyb_write_color_span(ant=%d,x=%d,y=%d)",n,x,y);*/
  605.  
  606.     if(dp = (ULONG*)amesa->imageline)
  607.     {           /* if imageline allocated then use fastversion */
  608. DEBUGOUT("FAST ")
  609.         if (mask)
  610.             {
  611. DEBUGOUT("mask\n")
  612.             ant=0;
  613.             for (i=0;i<n;i++)           /* draw pixel (x[i],y[i]) */
  614.                 {
  615.                 if (mask[i])
  616.                     {
  617.                     ant++;
  618.                     *dp = TC_RGBA(red[i],green[i],blue[i],alpha[i]);dp++;
  619.                     }
  620.                 else
  621.                     {
  622.                     if(ant)
  623.                         {
  624.                         WritePixelArray(amesa->imageline,0,0,4*ant,rp,x,y,ant,1,RECTFMT_ARGB);
  625. /*printf("WritePixelArray(ant=%d,x=%d,y=%d)\n",ant,x,y);*/
  626.                         dp=(ULONG*)amesa->imageline;
  627.                         ant=0;
  628.                         x=x+ant;
  629.                         }
  630.                     x++;
  631.                     }
  632.                 }
  633.  
  634.             if(ant)
  635.                 {
  636.                 WritePixelArray(amesa->imageline,0,0,4*ant,rp,x,y,ant,1,RECTFMT_ARGB);
  637. /*printf("WritePixelArray(ant=%d,x=%d,y=%d)\n",ant,x,y);*/
  638.                 }
  639.             }
  640.         else
  641.             {
  642. DEBUGOUT("nomask\n")
  643.             for (i=0;i<n;i++)                   /* draw pixel (x[i],y[i])*/
  644.                 {
  645.                 *dp = TC_RGBA(red[i],green[i],blue[i],alpha[i]);dp++;
  646.                 }
  647.             WritePixelArray(amesa->imageline,0,0,4*n,rp,x,y,n,1,RECTFMT_ARGB);
  648.             }
  649.         
  650.         }
  651.     else
  652.         {    /* Slower version */
  653. DEBUGOUT("FAST\n")
  654.         if (mask)
  655.             {
  656. DEBUGOUT("mask\n")
  657.             /* draw some pixels */
  658.             for (i=0; i<n; i++, x++)
  659.                 {
  660.                 if (mask[i])
  661.                     {
  662.                     /* draw pixel x,y using color red[i]/green[i]/blue[i]/alpha[i] */
  663.                     WriteRGBPixel(rp,x,y,TC_RGBA(red[i],green[i],blue[i],alpha[i]));
  664.                     }
  665.                 }
  666.             }
  667.         else
  668.             {
  669. DEBUGOUT("nomask\n")
  670.             /* draw all pixels */
  671.             for (i=0; i<n; i++, x++)
  672.                 {
  673.                 /* draw pixel x,y using color red[i]/green[i]/blue[i]/alpha[i] */
  674.                 WriteRGBPixel(rp,x,y,TC_RGBA(red[i],green[i],blue[i],alpha[i]));
  675.                 }
  676.             }
  677.         }
  678. }
  679.  
  680.  
  681.  
  682.  
  683. static void cyb_write_monoindex_span(GLcontext *ctx,GLuint n,GLint x,GLint y,const GLubyte mask[])
  684. {
  685.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  686.     int i,j;
  687.     y=FIXy(y);
  688.     x=FIXx(x);
  689.  
  690.  
  691. DEBUGOUT("cyb_write_monoindex_span\n")
  692.  
  693.  
  694.     i=0;
  695.     while(i<n)
  696.         {
  697.         while(!mask[i] && i<n)
  698.             {
  699.             i++;x++;
  700.             }
  701.  
  702.         if(i<n)
  703.             {
  704.             j=0;
  705.             while(mask[i] && i<n)
  706.                 {
  707.                 i++;j++;
  708.                 }
  709.             FillPixelArray (amesa->rp,x,y,j,1,amesa->pixel);
  710.             }
  711.         }
  712. }
  713.  
  714. static void cyb_write_monocolor_span( GLcontext *ctx,GLuint n, GLint x, GLint y,
  715.                                              const GLubyte mask[])
  716. {
  717.     AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  718.     int i,j;
  719.     register struct RastPort * rp = amesa->rp;
  720.  
  721. /*printf("cyb_write_monocolor_span(%d,%d,%d)\n",n,x,y);*/
  722. DEBUGOUT("cyb_write_monocolor_span(n,x,y)\n")
  723.  
  724.     y=FIXy(y);
  725.     x=FIXx(x);
  726.     i=0;
  727.     while(i<n)
  728.         {
  729.         while(!mask[i] && i<n)
  730.             {
  731.             i++;
  732.             x++;
  733.             }
  734.  
  735.         if(i<n)
  736.             {
  737.             j = 0;
  738.             while(mask[i] && i<n)
  739.                 {
  740.                 i++;
  741.                 j++;
  742.                 }
  743.             FillPixelArray(rp,x,y,j,1,amesa->pixel);
  744.             }
  745.         }
  746. }
  747.  
  748.  
  749. /**********************************************************************/
  750. /*****                    Read spans of pixels                              *****/
  751. /**********************************************************************/
  752.  
  753. /* Here we should check if the size of the colortable is <256 */
  754.  
  755. static void cyb_read_index_span( GLcontext *ctx,GLuint n, GLint x, GLint y, GLuint index[])
  756. {
  757.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  758.  
  759.     int i;
  760.  
  761. DEBUGOUT("cyb_read_index_span>>\n")
  762.  
  763.  
  764.     y=FIXy(y);
  765.     x=FIXx(x);
  766.  
  767.     // Currently this is wrong ARGB-values are NO indexes !!!
  768.     if(amesa->imageline) {
  769.         ReadPixelArray(amesa->imageline,0,0,4*n,amesa->rp,x,y,n,1,RECTFMT_ARGB);
  770.         for(i=0; i<n; i++)
  771.             index[i]=((ULONG*)amesa->imageline)[i];
  772.     } else {
  773.         for (i=0; i<n; i++,x++)
  774.             index[i] = ReadRGBPixel(amesa->rp,x,y);
  775.     }
  776. }
  777.  
  778. static void MyReadPixelArray(UBYTE *a, ULONG b, ULONG c, ULONG d, struct RastPort *e,ULONG f, ULONG g,ULONG h, ULONG i,ULONG j)
  779. {
  780.     ReadPixelArray(a,b,c,d,e,f,g,h,i,j);
  781. }
  782.  
  783. static void cyb_read_color_span( GLcontext *ctx,GLuint n, GLint x, GLint y,
  784.                                       GLubyte red[], GLubyte green[],
  785.                                       GLubyte blue[], GLubyte alpha[] )
  786. {
  787.     AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  788.     int i;
  789.     ULONG col;
  790.  
  791. DEBUGOUT("cyb_read_color_span>>\n")
  792.  
  793.  
  794.     y=FIXy(y);
  795.     x=FIXx(x);
  796.  
  797.     if(amesa->imageline) {
  798.         MyReadPixelArray(amesa->imageline,0,0,n*4,amesa->rp,x,y,n,1,RECTFMT_ARGB);
  799.         for(i=0; i<n; i++) {
  800.             col = ((ULONG*)amesa->imageline)[i];
  801.             red[i] = (col & 0xff0000)>>16;
  802.             green[i] = (col & 0xff00)>>8;
  803.             blue[i] = col & 0xff;
  804.             alpha[i]= (col & 0xff000000)>>24;
  805.         }
  806.     } else
  807.         for (i=0; i<n; i++, x++) {
  808.             col=ReadRGBPixel(amesa->rp,x,y);
  809.             red[i] = (col & 0xff0000)>>16;
  810.             green[i] = (col & 0xff00)>>8;
  811.             blue[i] = col & 0xff;
  812.             alpha[i]= (col & 0xff000000)>>24;
  813.             }
  814. }
  815.  
  816.  
  817.  
  818.  
  819. /**********************************************************************/
  820. /*****                Write arrays of pixels                      *****/
  821. /**********************************************************************/
  822.  
  823. static void cyb_write_index_pixels_db( GLcontext *ctx,GLuint n, const GLint x[], const GLint y[],
  824.                                           const GLuint index[], const GLubyte mask[] )
  825. {
  826.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  827.  
  828.     int i;
  829. //  register struct RastPort * rp = amesa->rp;
  830. DEBUGOUT("awrite_index_pixels<\n")
  831.  
  832.     for (i=0; i<n; i++)
  833.         {
  834.         if (mask[i])
  835.             {
  836.             ((ULONG*)amesa->BackArray)[FIXxy(x[i],y[i])]=amesa->penconv[index[i]];
  837.             }
  838.         }
  839. }
  840.  
  841. static void cyb_write_monoindex_pixels_db( GLcontext *ctx,GLuint n,
  842.                                                 const GLint x[], const GLint y[],
  843.                                                 const GLubyte mask[] )
  844. {
  845.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  846.     int i;
  847. //  register struct RastPort * rp = amesa->rp;
  848. DEBUGOUT("awrite_index_pixels<\n")
  849.  
  850.     for (i=0; i<n; i++)
  851.         {
  852.         if (mask[i])
  853.             {
  854.             ((ULONG*)amesa->BackArray)[FIXxy(x[i],y[i])]=amesa->pixel;
  855.             }
  856.         }
  857. }
  858.  
  859. static void cyb_write_color_pixels_db(GLcontext *ctx, GLuint n, const GLint x[], const GLint y[],
  860.                                               const GLubyte r[], const GLubyte g[],
  861.                                               const GLubyte b[], const GLubyte a[],
  862.                                               const GLubyte mask[] )
  863. {
  864.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  865.     int i;
  866. //  register struct RastPort * rp = amesa->rp;
  867. DEBUGOUT("cyb_write_index_pixels<\n")
  868.  
  869.     for (i=0; i<n; i++)
  870.         {
  871.         if (mask[i])
  872.             {
  873.             ((ULONG*)amesa->BackArray)[FIXxy(x[i],y[i])]=TC_RGBA(r[i],g[i],b[i],a[i]);
  874.             }
  875.         }
  876. }
  877.  
  878.  
  879. static void cyb_write_index_pixels(GLcontext *ctx, GLuint n, const GLint x[], const GLint y[],
  880.                                           const GLuint index[], const GLubyte mask[] )
  881. {
  882.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  883.     int i;
  884.     register struct RastPort * rp = amesa->rp;
  885. DEBUGOUT("awrite_index_pixels<\n")
  886.  
  887.     for (i=0; i<n; i++)
  888.         {
  889.         if (mask[i])
  890.             {
  891.             WriteRGBPixel(rp,FIXx(x[i]),FIXy(y[i]),amesa->penconv[index[i]]);
  892.             }
  893.         }
  894. }
  895.  
  896.  
  897. static void cyb_write_monoindex_pixels(GLcontext *ctx, GLuint n,
  898.                                                 const GLint x[], const GLint y[],
  899.                                                 const GLubyte mask[] )
  900. {
  901.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  902.     int i;
  903.     register struct RastPort * rp = amesa->rp;
  904.  
  905. DEBUGOUT("cyb_write_monoindex_pixels<\n");
  906.  
  907.     for (i=0; i<n; i++) {
  908.         if (mask[i]) {
  909. /*        write pixel x[i], y[i] using current index  */
  910.         WriteRGBPixel(rp,FIXx(x[i]),FIXy(y[i]),amesa->pixel);
  911.  
  912.         }
  913.     }
  914. }
  915.  
  916.  
  917.  
  918. static void cyb_write_color_pixels( GLcontext *ctx,GLuint n, const GLint x[], const GLint y[],
  919.                                           const GLubyte r[], const GLubyte g[],
  920.                                           const GLubyte b[], const GLubyte a[],
  921.                                           const GLubyte mask[] )
  922. {
  923.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  924.     int i;
  925.     register struct RastPort * rp = amesa->rp;
  926.  
  927. DEBUGOUT("cyb_write_color_pixels<\n")
  928.  
  929.     for (i=0; i<n; i++) {
  930.         if (mask[i]) {
  931. /*        write pixel x[i], y[i] using red[i],green[i],blue[i],alpha[i] */
  932.         WriteRGBPixel(rp,FIXx(x[i]),FIXy(y[i]),TC_RGBA(r[i],g[i],b[i],a[i]));
  933.         }
  934.     }
  935. }
  936.  
  937.  
  938.  
  939. static void cyb_write_monocolor_pixels(GLcontext *ctx, GLuint n,
  940.                                                 const GLint x[], const GLint y[],
  941.                                                 const GLubyte mask[] )
  942. {
  943.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  944.     int i;
  945.     register struct RastPort * rp = amesa->rp;
  946.  
  947. DEBUGOUT("cyb_write_monocolor_pixels<\n")
  948.  
  949.     for (i=0; i<n; i++) {
  950.         if (mask[i]) {
  951. /*        write pixel x[i], y[i] using current color*/
  952.         WriteRGBPixel(rp,FIXx(x[i]),FIXy(y[i]),amesa->pixel);
  953.         }
  954.     }
  955. }
  956.  
  957.  
  958.  
  959.  
  960. /**********************************************************************/
  961. /*****                       Read arrays of pixels                          *****/
  962. /**********************************************************************/
  963.  
  964. /* Read an array of color index pixels. */
  965. static void cyb_read_index_pixels( GLcontext *ctx,GLuint n, const GLint x[], const GLint y[],
  966.                                          GLuint index[], const GLubyte mask[] )
  967. {
  968.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  969.     int i;
  970.     register struct RastPort * rp = amesa->rp;
  971.  
  972. DEBUGOUT("cyb_read_index_pixels-\n")
  973.     
  974.  
  975.   for (i=0; i<n; i++) {
  976.       if (mask[i]) {
  977. /*       index[i] = read_pixel x[i], y[i] */
  978.         index[i] = ReadRGBPixel(rp,FIXx(x[i]),FIXy(y[i])); // that's wrong! we get ARGB!
  979.       }
  980.   }
  981. }
  982.  
  983. static void cyb_read_color_pixels( GLcontext *ctx,GLuint n, const GLint x[], const GLint y[],
  984.                                          GLubyte red[], GLubyte green[],
  985.                                          GLubyte blue[], GLubyte alpha[],
  986.                                          const GLubyte mask[] )
  987. {
  988.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  989.     int i,col;
  990.     register struct RastPort * rp = amesa->rp;
  991.  
  992. //  ULONG ColTab[3];
  993.  
  994. DEBUGOUT("cyb_read_color_pixels-\n")
  995.         
  996.  
  997.     for (i=0; i<n; i++)
  998.         {
  999.         if (mask[i])
  1000.             {
  1001.             col=ReadRGBPixel(rp,FIXx(x[i]),FIXy(y[i]));
  1002.  
  1003.             red[i]  = (col&0xff0000)>>16;
  1004.             green[i] = (col&0xff00)>>8;
  1005.             blue[i] = col&0xff;
  1006.             alpha[i]= (col&0xff000000)>>24;
  1007.         }
  1008.     }
  1009. }
  1010.  
  1011.  
  1012. /**********************************************************************/
  1013. /**********************************************************************/
  1014.  
  1015. static GLboolean cyb_set_buffer( GLcontext *ctx,GLenum mode )
  1016. {
  1017.     /* set the current drawing/reading buffer, return GL_TRUE or GL_FALSE */
  1018.     /* for success/failure */
  1019.     
  1020. /*   AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx; */
  1021.  
  1022.  
  1023. DEBUGOUT("cyb_set_buffer TODO\n")
  1024.     
  1025.  
  1026. /* TODO implemed a set of buffers */
  1027.     if (mode==GL_FRONT)
  1028.         {
  1029.         return(GL_TRUE);
  1030.         }
  1031.     else if (mode==GL_BACK)
  1032.         {
  1033.         return(GL_TRUE);
  1034.         }
  1035.     else
  1036.         {
  1037.         return(GL_FALSE);
  1038.         }
  1039. }
  1040.  
  1041.  
  1042.  
  1043.  
  1044. /**********************************************************************/
  1045. /**********************************************************************/
  1046.     /* Initialize all the pointers in the DD struct.  Do this whenever   */
  1047.     /* a new context is made current or we change buffers via set_buffer! */
  1048. void cyb_standard_DD_pointers( GLcontext *ctx )
  1049. {
  1050. //   AmigaMesaContext amesa = ctx->DriverCtx;
  1051.  
  1052. DEBUGOUT("Inside cyb_standard_DD_pointers\n")
  1053. #ifdef DEBUGPRINT
  1054. printf("ctx=0x%x\n",ctx);
  1055. printf("CC=0x%x\n",CC);
  1056. #endif
  1057.  
  1058. //  ctx=CC;  /* BRUTE FORCE OVERERIDE REMOVE PLEASE */
  1059.  
  1060.  
  1061.    ctx->Driver.UpdateState = cyb_standard_DD_pointers;
  1062.    ctx->Driver.ClearIndex = cyb_clear_index;
  1063.    ctx->Driver.ClearColor = cyb_clear_color;
  1064.    ctx->Driver.Clear = cyb_clear;
  1065.  
  1066.    ctx->Driver.Index = cyb_set_index;
  1067.    ctx->Driver.Color = cyb_set_color;
  1068.  
  1069.    ctx->Driver.IndexMask = cyb_index_mask;
  1070.    ctx->Driver.ColorMask = cyb_color_mask;
  1071.  
  1072.    ctx->Driver.SetBuffer = cyb_set_buffer;
  1073.    ctx->Driver.GetBufferSize = Cyb_Standard_resize;
  1074.  
  1075.    ctx->Driver.PointsFunc = cyb_choose_points_function( ctx );
  1076.    ctx->Driver.LineFunc = cyb_choose_line_function( ctx );
  1077. //   ctx->Driver.PolygonFunc = cyb_choose_polygon_function( ctx );
  1078.     ctx->Driver.TriangleFunc = FALSE;  //TODO
  1079.  
  1080.    /* Pixel/span writing functions: */
  1081.    ctx->Driver.WriteColorSpan       = cyb_write_color_span;
  1082.    ctx->Driver.WriteMonocolorSpan   = cyb_write_monocolor_span;
  1083.    ctx->Driver.WriteColorPixels     = cyb_write_color_pixels;
  1084.    ctx->Driver.WriteMonocolorPixels = cyb_write_monocolor_pixels;
  1085.    ctx->Driver.WriteIndexSpan       = cyb_write_index_span;
  1086.    ctx->Driver.WriteMonoindexSpan   = cyb_write_monoindex_span;
  1087.    ctx->Driver.WriteIndexPixels     = cyb_write_index_pixels;
  1088.    ctx->Driver.WriteMonoindexPixels = cyb_write_monoindex_pixels;
  1089.  
  1090.    /* Pixel/span reading functions: */
  1091.    ctx->Driver.ReadIndexSpan = cyb_read_index_span;
  1092.    ctx->Driver.ReadColorSpan = cyb_read_color_span;
  1093.    ctx->Driver.ReadIndexPixels = cyb_read_index_pixels;
  1094.    ctx->Driver.ReadColorPixels = cyb_read_color_pixels;
  1095. }
  1096.  
  1097. void cyb_Faster_DD_pointers( GLcontext *ctx )
  1098. {
  1099.     ctx=CC;  /* BRUTE FORCE OVERERIDE REMOVE PLEASE */
  1100.  
  1101.    ctx->Driver.UpdateState = cyb_Faster_DD_pointers;
  1102.    ctx->Driver.ClearIndex = cyb_clear_index;
  1103.    ctx->Driver.ClearColor = cyb_clear_color;
  1104.    ctx->Driver.Clear = cyb_clear_db;
  1105.  
  1106.    ctx->Driver.Index = cyb_set_index;
  1107.    ctx->Driver.Color = cyb_set_color;
  1108.  
  1109.    ctx->Driver.IndexMask = cyb_index_mask;
  1110.    ctx->Driver.ColorMask = cyb_color_mask;
  1111.  
  1112.    ctx->Driver.SetBuffer = cyb_set_buffer;
  1113.    ctx->Driver.GetBufferSize = Cyb_Standard_resize_db;
  1114.  
  1115.    ctx->Driver.PointsFunc = cyb_choose_points_function_db( ctx );
  1116.    ctx->Driver.LineFunc = cyb_choose_line_function_db( ctx );
  1117. //   ctx->Driver.PolygonFunc = cyb_choose_polygon_function_db( ctx );
  1118.     ctx->Driver.TriangleFunc = FALSE;  //TODO
  1119.  
  1120.    /* Pixel/span writing functions: */
  1121.    ctx->Driver.WriteColorSpan       = cyb_write_color_span_db;
  1122.    ctx->Driver.WriteMonocolorSpan   = cyb_write_monoindex_span_db; /* same */
  1123.    ctx->Driver.WriteColorPixels     = cyb_write_color_pixels_db;
  1124.    ctx->Driver.WriteMonocolorPixels = cyb_write_monoindex_pixels_db;   /* same */
  1125.    ctx->Driver.WriteIndexSpan       = cyb_write_index_span_db;
  1126.    ctx->Driver.WriteMonoindexSpan   = cyb_write_monoindex_span_db;
  1127.    ctx->Driver.WriteIndexPixels     = cyb_write_index_pixels_db;
  1128.    ctx->Driver.WriteMonoindexPixels = cyb_write_monoindex_pixels_db;
  1129.  
  1130.    /* Pixel/span reading functions: */
  1131.    ctx->Driver.ReadIndexSpan = cyb_read_index_span;
  1132.    ctx->Driver.ReadColorSpan = cyb_read_color_span;
  1133.    ctx->Driver.ReadIndexPixels = cyb_read_index_pixels;
  1134.    ctx->Driver.ReadColorPixels = cyb_read_color_pixels;
  1135. }
  1136.  
  1137.  
  1138. /**********************************************************************/
  1139. /*****                  Amiga/Mesa private misc procedures        *****/
  1140. /**********************************************************************/
  1141.  
  1142. static void MyWritePixelArray(void *a,int b,int c,int d,struct RastPort *e,int f,int g, int h, int i, int j)
  1143. {
  1144.     WritePixelArray(a,b,c,d,e,f,g,h,i,j);
  1145. }
  1146.  
  1147. /**********************************************************************/
  1148. /***** AmigaMesaSetOneColor                                       *****/
  1149. /**********************************************************************/
  1150. void AmigaMesaSetOneColor(struct amigamesa_context *c,int index, float r, float g, float b)
  1151. {
  1152.     if (c->depth>8) {
  1153.         c->penconv[index] = TC_RGBA((int)r*255,(int)g*255,(int)b*255,255);
  1154.     } else {
  1155.         c->penconv[index] = RGBA(c,r*255,g*255,b*255,255);
  1156.     }
  1157. }
  1158.  
  1159.  
  1160.  
  1161. static void
  1162. Cyb_Standard_resize( GLcontext *ctx,GLuint *width, GLuint *height)
  1163.     {
  1164.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  1165.  
  1166. DEBUGOUT("Cyb_Standard_resize\n")
  1167.     *width=amesa->width;
  1168.     *height=amesa->height;
  1169.  
  1170.     if(!((  amesa->width  == (amesa->front_rp->Layer->bounds.MaxX-amesa->front_rp->Layer->bounds.MinX-amesa->left) )
  1171.     &&  ( amesa->height == (amesa->front_rp->Layer->bounds.MaxY-amesa->front_rp->Layer->bounds.MinY-amesa->bottom)  )))
  1172.         {
  1173.         FreeOneLine(amesa);
  1174.  
  1175.         amesa->FixedWidth =amesa->RealWidth =amesa->front_rp->Layer->bounds.MaxX-amesa->front_rp->Layer->bounds.MinX;
  1176.         amesa->FixedHeight=amesa->RealHeight=amesa->front_rp->Layer->bounds.MaxY-amesa->front_rp->Layer->bounds.MinY;
  1177.  
  1178.         *width=amesa->width = amesa->RealWidth-amesa->left;
  1179.         *height=amesa->height = amesa->RealHeight-amesa->bottom;
  1180.         amesa->depth = GetCyberMapAttr(amesa->front_rp->BitMap,CYBRMATTR_DEPTH);
  1181.  
  1182.         if (amesa->visual->db_flag) {
  1183.             if (amesa->back_rp) {   /* Free double buffer */
  1184.                 destroy_rastport(amesa->back_rp);
  1185.             }
  1186.             if((amesa->back_rp = make_rastport(amesa->RealWidth,amesa->RealHeight,amesa->depth,amesa->rp->BitMap))==NULL) {
  1187.                 amesa->rp = amesa->front_rp;
  1188.                 printf("To little mem free. Couldn't allocate Dubblebuffer in this size.\n");
  1189.             } else {
  1190.                 amesa->rp=amesa->back_rp;
  1191.             }
  1192.         }
  1193.  
  1194.         AllocOneLine(amesa);
  1195.         }
  1196.     }
  1197.  
  1198. static void
  1199. Cyb_Standard_resize_db( GLcontext *ctx,GLuint *width, GLuint *height)
  1200.     {
  1201.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  1202.  
  1203. DEBUGOUT("Cyb_Standard_resize_db\n")
  1204.  
  1205.     *width=amesa->width;
  1206.     *height=amesa->height;
  1207.  
  1208.     if(!((  amesa->width  == (amesa->rp->Layer->bounds.MaxX-amesa->rp->Layer->bounds.MinX-amesa->left) )
  1209.     &&  ( amesa->height == (amesa->rp->Layer->bounds.MaxY-amesa->rp->Layer->bounds.MinY-amesa->bottom)  )))
  1210.         {
  1211.  
  1212.         amesa->RealWidth =amesa->rp->Layer->bounds.MaxX-amesa->rp->Layer->bounds.MinX;
  1213.         amesa->RealHeight=amesa->rp->Layer->bounds.MaxY-amesa->rp->Layer->bounds.MinY;
  1214.         amesa->FixedWidth =(amesa->RealWidth+3)&0xfffffffc;
  1215.         amesa->FixedHeight=amesa->RealHeight+1;
  1216.  
  1217.  
  1218.         *width=amesa->width = amesa->RealWidth-amesa->left;
  1219.         *height=amesa->height = amesa->RealHeight-amesa->bottom;
  1220. //      amesa->left = 0;
  1221. //      amesa->bottom = 0;
  1222.         amesa->depth = GetCyberMapAttr(amesa->rp->BitMap,CYBRMATTR_DEPTH);
  1223.  
  1224.         if (amesa->visual->db_flag && amesa->BackArray)
  1225.             {
  1226.             destroy_penbackarray(amesa->BackArray);
  1227.             if(!(amesa->BackArray=alloc_penbackarray(amesa->RealWidth,amesa->RealHeight,4)))
  1228.                 {
  1229.                 printf("AmigaMesa Error Can't allocate new PenArray in that size.\n");
  1230. //              Amiga_Standard_init(amesa);
  1231.  
  1232.                 }
  1233.             }
  1234.  
  1235. #ifdef DEBUGPRINT
  1236.     printf("amesa->RealWidth =%d\n",amesa->RealWidth);
  1237.     printf("amesa->RealHeight=%d\n",amesa->RealHeight);
  1238.     printf("amesa->width =%d\n",amesa->width);
  1239.     printf("amesa->height=%d\n",amesa->height);
  1240.     printf("amesa->left  =%d\n",amesa->left);
  1241.     printf("amesa->bottom=%d\n",amesa->bottom);
  1242.     printf("amesa->depth =%d\n",amesa->depth);
  1243. #endif
  1244.  
  1245.         }
  1246.     }
  1247.  
  1248.  
  1249.  
  1250. /**********************************************************************/
  1251. /*****                  Amiga/Mesa private init/despose/resize       *****/
  1252. /**********************************************************************/
  1253.  
  1254. static void
  1255. Cyb_Standard_SwapBuffer_db(struct amigamesa_context *amesa)
  1256. {
  1257. DEBUGOUT("Amiga_Standard_SwapBuffer_db\n")
  1258.  
  1259.     if (amesa->depth>8) {
  1260.         MyWritePixelArray(amesa->BackArray,amesa->gl_ctx->Viewport.X,amesa->RealHeight-amesa->gl_ctx->Viewport.Height-amesa->gl_ctx->Viewport.Y,
  1261.                         amesa->RealWidth*4,//(amesa->left+amesa->gl_ctx->Viewport.X+amesa->gl_ctx->Viewport.Width)*4,
  1262.                         amesa->rp,amesa->left+amesa->gl_ctx->Viewport.X,
  1263.                         amesa->RealHeight-amesa->bottom-amesa->gl_ctx->Viewport.Height-amesa->gl_ctx->Viewport.Y,
  1264.                         /*amesa->left+amesa->gl_ctx->Viewport.X+*/amesa->gl_ctx->Viewport.Width,
  1265.                         amesa->gl_ctx->Viewport.Height/*amesa->RealHeight-amesa->bottom-amesa->gl_ctx->Viewport.Y*/,
  1266.                         RECTFMT_ARGB);
  1267. /*      printf("WritePixelArray(%d,%d,%d,%d);\n",
  1268.                                               amesa->left+amesa->gl_ctx->Viewport.X,
  1269.                                      amesa->RealHeight-amesa->bottom-amesa->gl_ctx->Viewport.Height-amesa->gl_ctx->Viewport.Y,
  1270.                                      amesa->left+amesa->gl_ctx->Viewport.X+amesa->gl_ctx->Viewport.Width,
  1271.                                      amesa->RealHeight-amesa->bottom-amesa->gl_ctx->Viewport.Y);*/
  1272.     } else {
  1273. //      WriteChunkyPixels(amesa->rp,amesa->left,amesa->RealHeight-amesa->height,amesa->RealWidth,amesa->RealHeight-amesa->bottom,amesa->BackArray,amesa->RealWidth);
  1274.  
  1275.         WriteChunkyPixels/*WritePixelArray8*/(amesa->rp,amesa->left+amesa->gl_ctx->Viewport.X,
  1276.                                      amesa->RealHeight-amesa->bottom-amesa->gl_ctx->Viewport.Height-amesa->gl_ctx->Viewport.Y,
  1277.                                      amesa->left+amesa->gl_ctx->Viewport.X+amesa->gl_ctx->Viewport.Width-1,
  1278.                                      amesa->RealHeight-amesa->bottom-amesa->gl_ctx->Viewport.Y-1,
  1279.                                      amesa->BackArray+(amesa->RealHeight-amesa->bottom-amesa->gl_ctx->Viewport.Height-amesa->gl_ctx->Viewport.Y)*amesa->RealWidth+amesa->left+amesa->gl_ctx->Viewport.X,
  1280.                                      amesa->RealWidth/*amesa->temprp*/);
  1281. /*        WritePixelArray8(amesa->rp,amesa->left+amesa->gl_ctx->Viewport.X,
  1282.                                      amesa->RealHeight-amesa->bottom-amesa->gl_ctx->Viewport.Height-amesa->gl_ctx->Viewport.Y,
  1283.                                      amesa->left+amesa->gl_ctx->Viewport.X+amesa->gl_ctx->Viewport.Width,
  1284.                                      amesa->RealHeight-amesa->bottom-amesa->gl_ctx->Viewport.Y,
  1285.                                      amesa->BackArray,
  1286.                                      amesa->temprp);*/
  1287. /*      printf("WritePixelArray8(%d,%d,%d,%d);\n",
  1288.                                               amesa->left+amesa->gl_ctx->Viewport.X,
  1289.                                      amesa->RealHeight-amesa->bottom-amesa->gl_ctx->Viewport.Height-amesa->gl_ctx->Viewport.Y,
  1290.                                      amesa->left+amesa->gl_ctx->Viewport.X+amesa->gl_ctx->Viewport.Width,
  1291.                                      amesa->RealHeight-amesa->bottom-amesa->gl_ctx->Viewport.Y);
  1292. */
  1293.     }
  1294.  
  1295. }
  1296.  
  1297.  
  1298. BOOL
  1299. Cyb_Standard_init(struct amigamesa_context *c,struct TagItem *tagList)
  1300.     {
  1301. DEBUGOUT("Cyber_Standard_init\n")
  1302.     c->window=(struct Window *)GetTagData(AMA_Window,0,tagList);
  1303.     if (!c->window)
  1304.         {
  1305.         c->rp=(struct RastPort *)GetTagData(AMA_RastPort,0,tagList);
  1306.         if (!c->rp)
  1307.             {
  1308.             LastError=AMESA_RASTPORT_TAG_MISSING;
  1309.             return(FALSE);
  1310.             }
  1311.         c->Screen=(struct Screen *)GetTagData(AMA_Screen,0,tagList);
  1312.         if (!c->Screen)
  1313.             {
  1314.             LastError=AMESA_SCREEN_TAG_MISSING;
  1315.             return(FALSE);
  1316.             }
  1317.         }
  1318.     else
  1319.         {
  1320.         c->rp =c->window->RPort;
  1321.         c->Screen=c->window->WScreen;
  1322.         }
  1323.  
  1324.     c->FixedWidth =c->RealWidth =c->rp->Layer->bounds.MaxX-c->rp->Layer->bounds.MinX;
  1325.     c->FixedHeight=c->RealHeight=c->rp->Layer->bounds.MaxY-c->rp->Layer->bounds.MinY;
  1326.  
  1327.     c->left = GetTagData(AMA_Left,0,tagList);
  1328.     c->bottom= GetTagData(AMA_Bottom,0,tagList);
  1329.  
  1330.  
  1331.     c->front_rp =c->rp;
  1332.     c->back_rp=NULL;
  1333. //  c->rp = c->front_rp;
  1334.  
  1335.  
  1336.     c->width = GetTagData(AMA_Width,c->RealWidth-c->left,tagList);
  1337.     c->height= GetTagData(AMA_Height,c->RealHeight-c->bottom,tagList);
  1338.  
  1339.     if (CyberGfxBase!=NULL && IsCyberModeID(GetVPModeID(&c->Screen->ViewPort)))
  1340.         {
  1341.         c->depth = GetCyberMapAttr(c->rp->BitMap,CYBRMATTR_DEPTH);
  1342.         } 
  1343.     else
  1344.         {
  1345.         c->depth = GetBitMapAttr(c->rp->BitMap,BMA_DEPTH);
  1346.         }
  1347.  
  1348.  
  1349. //  c->gl_ctx->BufferWidth = c->width;
  1350. //  c->gl_ctx->BufferHeight = c->height;
  1351.  
  1352.     c->pixel = 0;   /* current drawing pen */
  1353.  
  1354.  
  1355.     if (c->depth<=8)
  1356.         {
  1357.         AllocCMap(c->Screen);
  1358.         }
  1359.  
  1360.     if (c->visual->db_flag==GL_TRUE)
  1361.         {
  1362. DEBUGOUT("Dubelbuff inside amigastandard")
  1363.         if((c->back_rp = make_rastport(c->RealWidth,c->RealHeight,c->depth, c->rp->BitMap))!=NULL)
  1364.             {
  1365.             c->gl_ctx->Color.DrawBuffer = GL_BACK;
  1366.             c->rp = c->back_rp;
  1367.             }
  1368.         else
  1369.             {
  1370.             printf("make_rastport Faild\n");
  1371.             c->gl_ctx->Color.DrawBuffer = GL_FRONT;
  1372.             }
  1373.         }
  1374.     else
  1375.         {
  1376.         c->gl_ctx->Color.DrawBuffer = GL_FRONT;
  1377.         }
  1378.     AllocOneLine(c); /* A linebuffer for WritePixelLine */
  1379.  
  1380. /* this shall not be invoked att all if not cybergfx
  1381.     if (c->depth<=8) {
  1382.         if (!make_temp_raster( c->rp ))
  1383.             printf("Error allocating TmpRastPort\n");*/
  1384.         /* JAM: Added alloc_temp_rastport */
  1385. /*        alloc_temp_rastport(c);
  1386.         allocarea(c->rp);
  1387.     }
  1388. */
  1389.     c->InitDD=c->depth<=8 ? amiga_standard_DD_pointers : cyb_standard_DD_pointers;  /*standard drawing*/
  1390.     c->Dispose=Amiga_Standard_Dispose;
  1391.     c->SwapBuffer=Amiga_Standard_SwapBuffer;
  1392.  
  1393.  
  1394. #ifdef DEBUGPRINT
  1395.     printf("c->RealWidth =%d\n",c->RealWidth);
  1396.     printf("c->RealHeight=%d\n",c->RealHeight);
  1397.     printf("c->width =%d\n",c->width);
  1398.     printf("c->height=%d\n",c->height);
  1399.     printf("c->left  =%d\n",c->left);
  1400.     printf("c->bottom=%d\n",c->bottom);
  1401.     printf("c->depth =%d\n",c->depth);
  1402. #endif
  1403.  
  1404.     return(TRUE);
  1405.     }
  1406.  
  1407.  
  1408. BOOL
  1409. Cyb_Standard_init_db(struct amigamesa_context *c,struct TagItem *tagList)
  1410.     {
  1411. DEBUGOUT("Amiga_Standard_init_db\n")
  1412.     c->window=(struct Window *)GetTagData(AMA_Window,0,tagList);
  1413.     if (!c->window)
  1414.         {
  1415.         c->rp=(struct RastPort *)GetTagData(AMA_RastPort,0,tagList);
  1416.         if (!c->rp)
  1417.             {
  1418.             LastError=AMESA_RASTPORT_TAG_MISSING;
  1419.             return(FALSE);
  1420.             }
  1421.         c->Screen=(struct Screen *)GetTagData(AMA_Screen,0,tagList);
  1422.         if (!c->Screen)
  1423.             {
  1424.             LastError=AMESA_SCREEN_TAG_MISSING;
  1425.             return(FALSE);
  1426.             }
  1427.         }
  1428.     else
  1429.         {
  1430.         c->rp =c->window->RPort;
  1431.         c->Screen=c->window->WScreen;
  1432.         }
  1433.  
  1434.     if (CyberGfxBase!=NULL && IsCyberModeID(GetVPModeID(&c->Screen->ViewPort)))
  1435.         {
  1436.         c->depth = GetCyberMapAttr(c->rp->BitMap,CYBRMATTR_DEPTH);
  1437.         } 
  1438.     else
  1439.         {
  1440.         c->depth = GetBitMapAttr(c->rp->BitMap,BMA_DEPTH);
  1441.         }
  1442.     c->RealWidth =c->rp->Layer->bounds.MaxX-c->rp->Layer->bounds.MinX;
  1443.     c->RealHeight=c->rp->Layer->bounds.MaxY-c->rp->Layer->bounds.MinY;
  1444.     if (c->depth<=8)
  1445.         {
  1446.         c->FixedWidth =((c->RealWidth+15)>>4)<<4;
  1447.         }
  1448.     else
  1449.         {
  1450.         c->FixedWidth =(c->RealWidth+3)&0xfffffffc;
  1451.         }
  1452.     c->FixedHeight=c->RealHeight+1;
  1453.  
  1454.  
  1455.     c->left = GetTagData(AMA_Left,0,tagList);
  1456.     c->bottom = GetTagData(AMA_Bottom,0,tagList);
  1457.  
  1458.     c->width = GetTagData(AMA_Width,c->RealWidth-c->left,tagList);
  1459.     c->height= GetTagData(AMA_Height,c->RealHeight-c->bottom,tagList);
  1460.  
  1461. /*
  1462.     c->gl_ctx->BufferWidth = c->width;
  1463.     c->gl_ctx->BufferHeight = c->height;
  1464. */
  1465. //  c->pixel = 0;   /* current drawing pen */
  1466.  
  1467.     if (c->depth<=8) {
  1468.         AllocCMap(c->Screen);    /* colormap */
  1469.         /* JAM: added alloc_temp_rastport */
  1470.         alloc_temp_rastport(c);
  1471.     }
  1472.  
  1473.  
  1474.     if (c->visual->db_flag)
  1475.         {
  1476.         c->BackArray=alloc_penbackarray(c->RealWidth,c->RealHeight,c->depth<=8 ? 1 : 4);
  1477. #ifdef DEBUGPRINT
  1478. printf("byte array at -------->0x%x ends at 0x%x size=0x%x (%d)\n",c->BackArray,c->BackArray+(((c->RealWidth+15)>>4)<<4)*(c->RealHeight+1),(((c->RealWidth+15)>>4)<<4)*(c->RealHeight+1),(((c->RealWidth+15)>>4)<<4)*(c->RealHeight+1));
  1479. #endif
  1480.         c->gl_ctx->Color.DrawBuffer = GL_BACK;
  1481.  
  1482.         c->InitDD=c->depth<=8 ? amiga_Faster_DD_pointers : cyb_Faster_DD_pointers;  /*fast drawing*/
  1483.         c->Dispose=Amiga_Standard_Dispose_db;
  1484.         c->SwapBuffer=Cyb_Standard_SwapBuffer_db;
  1485.         }
  1486.     else
  1487.         {
  1488.         c->gl_ctx->Color.DrawBuffer = GL_FRONT;
  1489.         return(FALSE);
  1490.         }
  1491. #ifdef DEBUGPRINT
  1492.     printf("c->RealWidth =%d\n",c->RealWidth);
  1493.     printf("c->RealHeight=%d\n",c->RealHeight);
  1494.     printf("c->width =%d\n",c->width);
  1495.     printf("c->height=%d\n",c->height);
  1496.     printf("c->left  =%d\n",c->left);
  1497.     printf("c->bottom=%d\n",c->bottom);
  1498.     printf("c->depth =%d\n",c->depth);
  1499. #endif
  1500.     return(TRUE);
  1501.     }
  1502.  
  1503.  
  1504.  
  1505.  
  1506. #undef DEBUGPRINT
  1507. #endif  /* the outcomment of cyberGfx */
  1508.  
  1509.